home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / bench / immediate.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  12KB  |  493 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  * dinomometer - a synthetic modeling benchmark for OpenGL
  19.  * by Mark Kilgard
  20.  * Silicon Graphics Inc.
  21.  * November 15, 1993
  22.  * $Revision: 1.1 $
  23.  * code for immediate mode rendering of the dinosaur model
  24.  */
  25.  
  26. #undef NORMAL3F
  27. #undef FUNC
  28.  
  29. #ifdef DoLighting
  30. #define NORMAL3F(x,y,z) glNormal3f(x, y, z)
  31. #define FUNC(name) name
  32. #else
  33. #define NORMAL3F(x,y,z)
  34. #define FUNC(name) name##NoLite
  35. #endif
  36.  
  37. void
  38. FUNC(renderBodySide)(void)
  39. {
  40.     glShadeModel(GL_SMOOTH);
  41.     glBegin(GL_TRIANGLES);
  42.     glVertex2f(8, 12);
  43.     glVertex2f(7, 15);
  44.     glVertex2f(7, 13);
  45.     glVertex2f(8, 16);
  46.     glVertex2f(7, 15);
  47.     glVertex2f(8, 12);
  48.     glVertex2f(11, 5);
  49.     glVertex2f(10, 13.5);
  50.     glVertex2f(10, 4);
  51.     glVertex2f(11, 11.5);
  52.     glVertex2f(10, 13.5);
  53.     glVertex2f(11, 5);
  54.     glVertex2f(13, 12);
  55.     glVertex2f(10, 13.5);
  56.     glVertex2f(11, 11.5);
  57.     glVertex2f(13, 13);
  58.     glVertex2f(10, 13.5);
  59.     glVertex2f(13, 12);
  60.     glVertex2f(1, 2);
  61.     glVertex2f(0, 3);
  62.     glVertex2f(1, 1);
  63.     glVertex2f(3, 2);
  64.     glVertex2f(1, 2);
  65.     glVertex2f(1, 1);
  66.     glEnd();
  67.     glBegin(GL_TRIANGLE_FAN);
  68.     glVertex2f(5, 1);
  69.     glVertex2f(4, 3);
  70.     glVertex2f(3, 2);
  71.     glVertex2f(1, 1);
  72.     glEnd();
  73.     glBegin(GL_TRIANGLES);
  74.     glVertex2f(6, 6);
  75.     glVertex2f(4, 3);
  76.     glVertex2f(5, 1);
  77.     glVertex2f(7, 11);
  78.     glVertex2f(6, 6);
  79.     glVertex2f(5, 1);
  80.     glVertex2f(8, 4);
  81.     glVertex2f(7, 11);
  82.     glVertex2f(5, 1);
  83.     glVertex2f(8, 12);
  84.     glVertex2f(7, 11);
  85.     glVertex2f(8, 4);
  86.     glVertex2f(8, 16);
  87.     glVertex2f(8, 12);
  88.     glVertex2f(8, 4);
  89.     glVertex2f(10, 4);
  90.     glVertex2f(8, 16);
  91.     glVertex2f(8, 4);
  92.     glVertex2f(10, 13.5);
  93.     glVertex2f(8, 16);
  94.     glVertex2f(10, 4);
  95.     glVertex2f(11, 16);
  96.     glVertex2f(8, 16);
  97.     glVertex2f(10, 13.5);
  98.     glVertex2f(13, 14);
  99.     glVertex2f(11, 16);
  100.     glVertex2f(10, 13.5);
  101.     glVertex2f(13, 15);
  102.     glVertex2f(11, 16);
  103.     glVertex2f(13, 14);
  104.     glEnd();
  105. }
  106.  
  107. void
  108. FUNC(renderBody)(void)
  109. {
  110.     if(backcull) glFrontFace(GL_CW);
  111.     glShadeModel(GL_FLAT);
  112.     glBegin(GL_QUAD_STRIP);
  113.     glVertex3f(0, 3, 0);
  114.     NORMAL3F(-0.894427, -0.447214, 0);
  115.     glVertex3f(0, 3, 3);
  116.     glVertex3f(1, 1, 0);
  117.     NORMAL3F(0, -1, 0);
  118.     glVertex3f(1, 1, 3);
  119.     glVertex3f(5, 1, 0);
  120.     NORMAL3F(0.707107, -0.707107, 0);
  121.     glVertex3f(5, 1, 3);
  122.     glVertex3f(8, 4, 0);
  123.     NORMAL3F(0, -1, 0);
  124.     glVertex3f(8, 4, 3);
  125.     glVertex3f(10, 4, 0);
  126.     NORMAL3F(0.707107, -0.707107, 0);
  127.     glVertex3f(10, 4, 3);
  128.     glVertex3f(11, 5, 0);
  129.     NORMAL3F(1, 0, 0);
  130.     glVertex3f(11, 5, 3);
  131.     glVertex3f(11, 11.5, 0);
  132.     NORMAL3F(0.242536, -0.970143, 0);
  133.     glVertex3f(11, 11.5, 3);
  134.     glVertex3f(13, 12, 0);
  135.     NORMAL3F(1, 0, 0);
  136.     glVertex3f(13, 12, 3);
  137.     glVertex3f(13, 13, 0);
  138.     NORMAL3F(0.164399, 0.986394, 0);
  139.     glVertex3f(13, 13, 3);
  140.     glVertex3f(10, 13.5, 0);
  141.     NORMAL3F(0.164399, -0.986394, 0);
  142.     glVertex3f(10, 13.5, 3);
  143.     glVertex3f(13, 14, 0);
  144.     NORMAL3F(1, 0, 0);
  145.     glVertex3f(13, 14, 3);
  146.     glVertex3f(13, 15, 0);
  147.     NORMAL3F(0.447214, 0.894427, 0);
  148.     glVertex3f(13, 15, 3);
  149.     glVertex3f(11, 16, 0);
  150.     NORMAL3F(0, 1, 0);
  151.     glVertex3f(11, 16, 3);
  152.     glVertex3f(8, 16, 0);
  153.     NORMAL3F(-0.707107, 0.707107, 0);
  154.     glVertex3f(8, 16, 3);
  155.     glVertex3f(7, 15, 0);
  156.     NORMAL3F(-1, 0, 0);
  157.     glVertex3f(7, 15, 3);
  158.     glVertex3f(7, 13, 0);
  159.     NORMAL3F(-0.707107, -0.707107, 0);
  160.     glVertex3f(7, 13, 3);
  161.     glVertex3f(8, 12, 0);
  162.     NORMAL3F(-0.707107, 0.707107, 0);
  163.     glVertex3f(8, 12, 3);
  164.     glVertex3f(7, 11, 0);
  165.     NORMAL3F(-0.980581, 0.196116, 0);
  166.     glVertex3f(7, 11, 3);
  167.     glVertex3f(6, 6, 0);
  168.     NORMAL3F(-0.83205, 0.5547, 0);
  169.     glVertex3f(6, 6, 3);
  170.     glVertex3f(4, 3, 0);
  171.     NORMAL3F(-0.707107, 0.707107, 0);
  172.     glVertex3f(4, 3, 3);
  173.     glVertex3f(3, 2, 0);
  174.     NORMAL3F(0, 1, 0);
  175.     glVertex3f(3, 2, 3);
  176.     glVertex3f(1, 2, 0);
  177.     NORMAL3F(0.707107, 0.707107, 0);
  178.     glVertex3f(1, 2, 3);
  179.     glVertex3f(0, 3, 0);
  180.     NORMAL3F(-0.894427, -0.447214, 0);
  181.     glVertex3f(0, 3, 3);
  182.     glEnd();
  183.     NORMAL3F(0.0, 0.0, -1.0);
  184.     FUNC(renderBodySide)();
  185.     glPushMatrix();
  186.     glTranslatef(0, 0, 3);
  187.     if(backcull) glFrontFace(GL_CCW);
  188.     NORMAL3F(0.0, 0.0, 1.0);
  189.     FUNC(renderBodySide)();
  190.     glPopMatrix();
  191. }
  192.  
  193. void
  194. FUNC(renderArmSide)(void)
  195. {
  196.     glShadeModel(GL_SMOOTH);
  197.     glBegin(GL_TRIANGLES);
  198.     glVertex2f(15, 10);
  199.     glVertex2f(14.5, 10);
  200.     glVertex2f(15, 9.5);
  201.     glVertex2f(15.5, 11);
  202.     glVertex2f(14.5, 10);
  203.     glVertex2f(15, 10);
  204.     glVertex2f(9, 11);
  205.     glVertex2f(8, 10);
  206.     glVertex2f(9, 9);
  207.     glVertex2f(10, 9);
  208.     glVertex2f(9, 11);
  209.     glVertex2f(9, 9);
  210.     glVertex2f(11, 11);
  211.     glVertex2f(9, 11);
  212.     glVertex2f(10, 9);
  213.     glVertex2f(13, 8);
  214.     glVertex2f(11, 11);
  215.     glVertex2f(10, 9);
  216.     glVertex2f(13, 9);
  217.     glVertex2f(11, 11);
  218.     glVertex2f(13, 8);
  219.     glVertex2f(14, 9);
  220.     glVertex2f(13, 9);
  221.     glVertex2f(13, 8);
  222.     glVertex2f(14, 10);
  223.     glVertex2f(13, 9);
  224.     glVertex2f(14, 9);
  225.     glVertex2f(14, 11);
  226.     glVertex2f(14, 10);
  227.     glVertex2f(14, 9);
  228.     glVertex2f(14.5, 10);
  229.     glVertex2f(14, 11);
  230.     glVertex2f(14, 9);
  231.     glVertex2f(15, 9.5);
  232.     glVertex2f(14.5, 10);
  233.     glVertex2f(14, 9);
  234.     glVertex2f(16, 9);
  235.     glVertex2f(15, 9.5);
  236.     glVertex2f(14, 9);
  237.     glVertex2f(16, 10);
  238.     glVertex2f(15, 10);
  239.     glVertex2f(15, 9.5);
  240.     glEnd();
  241. }
  242.  
  243. void
  244. FUNC(renderArm)(void)
  245. {
  246.     if(backcull) glFrontFace(GL_CW);
  247.     glShadeModel(GL_FLAT);
  248.     glBegin(GL_QUAD_STRIP);
  249.     glVertex3f(8, 10, 0);
  250.     NORMAL3F(-0.707107, -0.707107, 0);
  251.     glVertex3f(8, 10, 0.75);
  252.     glVertex3f(9, 9, 0);
  253.     NORMAL3F(0, -1, 0);
  254.     glVertex3f(9, 9, 0.75);
  255.     glVertex3f(10, 9, 0);
  256.     NORMAL3F(-0.316228, -0.948683, 0);
  257.     glVertex3f(10, 9, 0.75);
  258.     glVertex3f(13, 8, 0);
  259.     NORMAL3F(0.707107, -0.707107, 0);
  260.     glVertex3f(13, 8, 0.75);
  261.     glVertex3f(14, 9, 0);
  262.     NORMAL3F(0, -1, 0);
  263.     glVertex3f(14, 9, 0.75);
  264.     glVertex3f(16, 9, 0);
  265.     NORMAL3F(0.447214, 0.894427, 0);
  266.     glVertex3f(16, 9, 0.75);
  267.     glVertex3f(15, 9.5, 0);
  268.     NORMAL3F(0.447214, -0.894427, 0);
  269.     glVertex3f(15, 9.5, 0.75);
  270.     glVertex3f(16, 10, 0);
  271.     NORMAL3F(0, 1, 0);
  272.     glVertex3f(16, 10, 0.75);
  273.     glVertex3f(15, 10, 0);
  274.     NORMAL3F(0.894427, -0.447214, 0);
  275.     glVertex3f(15, 10, 0.75);
  276.     glVertex3f(15.5, 11, 0);
  277.     NORMAL3F(-0.707107, 0.707107, 0);
  278.     glVertex3f(15.5, 11, 0.75);
  279.     glVertex3f(14.5, 10, 0);
  280.     NORMAL3F(0.894427, 0.447214, 0);
  281.     glVertex3f(14.5, 10, 0.75);
  282.     glVertex3f(14, 11, 0);
  283.     NORMAL3F(-1, 0, 0);
  284.     glVertex3f(14, 11, 0.75);
  285.     glVertex3f(14, 10, 0);
  286.     NORMAL3F(-0.707107, 0.707107, 0);
  287.     glVertex3f(14, 10, 0.75);
  288.     glVertex3f(13, 9, 0);
  289.     NORMAL3F(0.707107, 0.707107, 0);
  290.     glVertex3f(13, 9, 0.75);
  291.     glVertex3f(11, 11, 0);
  292.     NORMAL3F(0, 1, 0);
  293.     glVertex3f(11, 11, 0.75);
  294.     glVertex3f(9, 11, 0);
  295.     NORMAL3F(-0.707107, 0.707107, 0);
  296.     glVertex3f(9, 11, 0.75);
  297.     glVertex3f(8, 10, 0);
  298.     NORMAL3F(-0.707107, -0.707107, 0);
  299.     glVertex3f(8, 10, 0.75);
  300.     glEnd();
  301.     NORMAL3F(0.0, 0.0, -1.0);
  302.     FUNC(renderArmSide)();
  303.     glPushMatrix();
  304.     glTranslatef(0, 0, 0.75);
  305.     if(backcull) glFrontFace(GL_CCW);
  306.     NORMAL3F(0.0, 0.0, 1.0);
  307.     FUNC(renderArmSide)();
  308.     glPopMatrix();
  309. }
  310.  
  311. void
  312. FUNC(renderLegSide)(void)
  313. {
  314.     glShadeModel(GL_SMOOTH);
  315.     glBegin(GL_TRIANGLES);
  316.     glVertex2f(9, 3);
  317.     glVertex2f(8, 6);
  318.     glVertex2f(8, 4);
  319.     glVertex2f(9, 7);
  320.     glVertex2f(8, 6);
  321.     glVertex2f(9, 3);
  322.     glVertex2f(9, 0);
  323.     glVertex2f(8, 1);
  324.     glVertex2f(8, 0.5);
  325.     glVertex2f(9, 2);
  326.     glVertex2f(8, 1);
  327.     glVertex2f(9, 0);
  328.     glVertex2f(9, 3);
  329.     glVertex2f(9, 2);
  330.     glVertex2f(9, 0);
  331.     glVertex2f(9, 7);
  332.     glVertex2f(9, 3);
  333.     glVertex2f(9, 0);
  334.     glVertex2f(10, 1);
  335.     glVertex2f(9, 7);
  336.     glVertex2f(9, 0);
  337.     glVertex2f(12, 0);
  338.     glVertex2f(10, 1);
  339.     glVertex2f(9, 0);
  340.     glVertex2f(10, 2);
  341.     glVertex2f(9, 7);
  342.     glVertex2f(10, 1);
  343.     glVertex2f(10, 7);
  344.     glVertex2f(9, 7);
  345.     glVertex2f(10, 2);
  346.     glVertex2f(11, 6);
  347.     glVertex2f(10, 7);
  348.     glVertex2f(10, 2);
  349.     glVertex2f(12, 4);
  350.     glVertex2f(11, 6);
  351.     glVertex2f(10, 2);
  352.     glEnd();
  353. }
  354.  
  355. void
  356. FUNC(renderLeg)(void)
  357. {
  358.     if(backcull) glFrontFace(GL_CW);
  359.     glShadeModel(GL_FLAT);
  360.     glBegin(GL_QUAD_STRIP);
  361.     glVertex3f(8, 6, 0);
  362.     NORMAL3F(-1, 0, 0);
  363.     glVertex3f(8, 6, 1.5);
  364.     glVertex3f(8, 4, 0);
  365.     NORMAL3F(-0.707107, -0.707107, 0);
  366.     glVertex3f(8, 4, 1.5);
  367.     glVertex3f(9, 3, 0);
  368.     NORMAL3F(-1, 0, 0);
  369.     glVertex3f(9, 3, 1.5);
  370.     glVertex3f(9, 2, 0);
  371.     NORMAL3F(-0.707107, 0.707107, 0);
  372.     glVertex3f(9, 2, 1.5);
  373.     glVertex3f(8, 1, 0);
  374.     NORMAL3F(-1, 0, 0);
  375.     glVertex3f(8, 1, 1.5);
  376.     glVertex3f(8, 0.5, 0);
  377.     NORMAL3F(-0.447214, -0.894427, 0);
  378.     glVertex3f(8, 0.5, 1.5);
  379.     glVertex3f(9, 0, 0);
  380.     NORMAL3F(0, -1, 0);
  381.     glVertex3f(9, 0, 1.5);
  382.     glVertex3f(12, 0, 0);
  383.     NORMAL3F(0.447214, 0.894427, 0);
  384.     glVertex3f(12, 0, 1.5);
  385.     glVertex3f(10, 1, 0);
  386.     NORMAL3F(1, 0, 0);
  387.     glVertex3f(10, 1, 1.5);
  388.     glVertex3f(10, 2, 0);
  389.     NORMAL3F(0.707107, -0.707107, 0);
  390.     glVertex3f(10, 2, 1.5);
  391.     glVertex3f(12, 4, 0);
  392.     NORMAL3F(0.894427, 0.447214, 0);
  393.     glVertex3f(12, 4, 1.5);
  394.     glVertex3f(11, 6, 0);
  395.     NORMAL3F(0.707107, 0.707107, 0);
  396.     glVertex3f(11, 6, 1.5);
  397.     glVertex3f(10, 7, 0);
  398.     NORMAL3F(0, 1, 0);
  399.     glVertex3f(10, 7, 1.5);
  400.     glVertex3f(9, 7, 0);
  401.     NORMAL3F(-0.707107, 0.707107, 0);
  402.     glVertex3f(9, 7, 1.5);
  403.     glVertex3f(8, 6, 0);
  404.     NORMAL3F(-1, 0, 0);
  405.     glVertex3f(8, 6, 1.5);
  406.     glEnd();
  407.     NORMAL3F(0.0, 0.0, -1.0);
  408.     FUNC(renderLegSide)();
  409.     glPushMatrix();
  410.     glTranslatef(0, 0, 1.5);
  411.     if(backcull) glFrontFace(GL_CCW);
  412.     NORMAL3F(0.0, 0.0, 1.0);
  413.     FUNC(renderLegSide)();
  414.     glPopMatrix();
  415. }
  416.  
  417. void
  418. FUNC(renderEyeSide)(void)
  419. {
  420.     glShadeModel(GL_SMOOTH);
  421.     glBegin(GL_TRIANGLES);
  422.     glVertex2f(9, 15.25);
  423.     glVertex2f(8.75, 15);
  424.     glVertex2f(9, 14.7);
  425.     glVertex2f(9.6, 14.7);
  426.     glVertex2f(9, 15.25);
  427.     glVertex2f(9, 14.7);
  428.     glVertex2f(9.6, 15.25);
  429.     glVertex2f(9, 15.25);
  430.     glVertex2f(9.6, 14.7);
  431.     glVertex2f(10.1, 15);
  432.     glVertex2f(9.6, 15.25);
  433.     glVertex2f(9.6, 14.7);
  434.     glEnd();
  435. }
  436.  
  437. void
  438. FUNC(renderEye)(void)
  439. {
  440.     if(backcull) glFrontFace(GL_CW);
  441.     glShadeModel(GL_FLAT);
  442.     glBegin(GL_QUAD_STRIP);
  443.     glVertex3f(8.75, 15, 0);
  444.     NORMAL3F(-0.768221, -0.640184, 0);
  445.     glVertex3f(8.75, 15, 3.2);
  446.     glVertex3f(9, 14.7, 0);
  447.     NORMAL3F(0, -1, 0);
  448.     glVertex3f(9, 14.7, 3.2);
  449.     glVertex3f(9.6, 14.7, 0);
  450.     NORMAL3F(0.514496, -0.857493, 0);
  451.     glVertex3f(9.6, 14.7, 3.2);
  452.     glVertex3f(10.1, 15, 0);
  453.     NORMAL3F(0.447214, 0.894427, 0);
  454.     glVertex3f(10.1, 15, 3.2);
  455.     glVertex3f(9.6, 15.25, 0);
  456.     NORMAL3F(0, 1, 0);
  457.     glVertex3f(9.6, 15.25, 3.2);
  458.     glVertex3f(9, 15.25, 0);
  459.     NORMAL3F(-0.707107, 0.707107, 0);
  460.     glVertex3f(9, 15.25, 3.2);
  461.     glVertex3f(8.75, 15, 0);
  462.     NORMAL3F(-0.768221, -0.640184, 0);
  463.     glVertex3f(8.75, 15, 3.2);
  464.     glEnd();
  465.     NORMAL3F(0.0, 0.0, -1.0);
  466.     FUNC(renderEyeSide)();
  467.     glPushMatrix();
  468.     glTranslatef(0, 0, 3.2);
  469.     if(backcull) glFrontFace(GL_CCW);
  470.     NORMAL3F(0.0, 0.0, 1.0);
  471.     FUNC(renderEyeSide)();
  472.     glPopMatrix();
  473. }
  474.  
  475. void
  476. FUNC(renderDinosaur)(void)
  477. {
  478.     glMaterialfv(GL_FRONT, GL_DIFFUSE, skinColor);
  479.     FUNC(renderBody)();
  480.     glPushMatrix();
  481.     glTranslatef(0, 0, 3);
  482.     FUNC(renderArm)();
  483.     FUNC(renderLeg)();
  484.     glTranslatef(0, 0, -3.75);
  485.     FUNC(renderArm)();
  486.     glTranslatef(0, 0, -0.75);
  487.     FUNC(renderLeg)();
  488.     glTranslatef(0, 0, 1.4);
  489.     glMaterialfv(GL_FRONT, GL_DIFFUSE, eyeColor);
  490.     FUNC(renderEye)();
  491.     glPopMatrix();
  492. }
  493.